#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>


#define PAGE_SIZE 4096

int main(void)
{
	int fd;
	char * buff;
	const char * str = "I am daoge...";
	char temp[256];
	fd = open("/dev/mmap_drv",O_RDWR);
	if(fd < 0)
	{
		perror("open");
		exit(1);
	}

	//实现映射
	buff = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	//写数据
	memcpy(buff, str, strlen(str));
    //读数据(测试)
	memset(temp, 0x00, sizeof(temp));
	read(fd, temp, strlen(str));
	printf("temp=%s\n", temp);
	
    munmap(buff, PAGE_SIZE);
	close(fd);
	return 0;
}
